//
//  TLRewardsTipsView.m
//  WXReader
//
//  Created by huaya on 2025/9/7.
//  Copyright © 2025 Andrew. All rights reserved.
//

#import "TLRewardsSuccessView.h"

@interface TLRewardsSuccessView ()
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;
@property (weak, nonatomic) IBOutlet UILabel *bonusLab;
@property (weak, nonatomic) IBOutlet UILabel *validDayLab;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentCenterY;
@end

@implementation TLRewardsSuccessView

+ (instancetype)createView {
    return [[[NSBundle mainBundle] loadNibNamed:@"TLRewardsSuccessView" owner:nil options:nil] lastObject];
}

- (void)awakeFromNib{
    [super awakeFromNib];
    self.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
    self.contentCenterY.constant = kScreenHeight;
    self.contentView.layer.cornerRadius = 10;
    
    self.closeBtn.layer.masksToBounds = YES;
    self.closeBtn.layer.cornerRadius = 20;
    
    [self layoutIfNeeded];
}

//展示从底部向上弹出的UIView（包含遮罩）
- (void)showInView:(UIView *)view andBonus:(NSNumber *)bonus andValid:(NSString *)validStr{
    if (!view)
    {
        return;
    }
    
    self.bonusLab.text = [NSString stringWithFormat:@"+%@",bonus];
    self.validDayLab.text = [NSString stringWithFormat:@"Valid in:%@ days",validStr];
    
    [view addSubview:self];
    
    [UIView animateWithDuration:0.5 animations:^{
    
         self.alpha = 1.0;
        self.contentCenterY.constant = -45;
        [self layoutIfNeeded];
    } completion:nil];
}


//移除从上向底部弹下去的UIView（包含遮罩）
- (void)disMissView
{

    [UIView animateWithDuration:0.5f
                     animations:^{
        
        self.alpha = 0.0;
        self.contentCenterY.constant = kScreenHeight;
        [self layoutIfNeeded];
    }
                     completion:^(BOOL finished){
        
        [self removeFromSuperview];
        [_contentView removeFromSuperview];
        
    }];
 
}
- (IBAction)closeAction:(id)sender {
    [self disMissView];
    
    MK_BLOCK_EXEC(self.reloadDataBlock);
}

@end
